package Exercise;
//字符串的调整
import java.util.Scanner;
public class String_8 {
    public static void main(String[] args) {
        String srs = "bcdea";
        //键盘录入
        Scanner sc = new Scanner(System.in);
        String sr;
        System.out.println("请输入字符串：");
        sr = sc.next();
        //判断
        if(Judge(sr,srs))
            System.out.println("匹配成功！");
        else
            System.out.println("匹配失败！");
    }
    public static boolean Judge(String sr,String srs){
        StringBuilder sb = new StringBuilder();
        int count = 0;  //统计移动次数
        for (int i = 0; i < sr.length(); i++) {
            //截取除第一个外的字符串，将第一个添加到字符串的末尾
            String s = sr.substring(1);
            sb = sb.append(s).append(sr.charAt(0));
            count++;
            if(srs.equals(sb.toString())){
                System.out.println("移动了"+count+"次");
                return true;
        }
        }
        return false;
    }
}
